package com.example.base_lib.util

import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.view.Window
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat

/**
 * 屏幕相关工具
 */

class ScreenUtil {
    /**
     * 设置沉浸式全屏
     */
     fun setFullscreen(activity:AppCompatActivity) {
        // 设置沉浸状态栏
         activity.window.statusBarColor = Color.TRANSPARENT
        WindowCompat.setDecorFitsSystemWindows(activity.window, false)
         activity.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        // 去除标题栏
         activity.requestWindowFeature(Window.FEATURE_NO_TITLE)
        // 隐藏标题栏
         activity.supportActionBar?.hide()
         setNavigationStatusColor(activity)
    }

    /**
     * 设置状态栏透明
     */
    private fun setNavigationStatusColor(activity:AppCompatActivity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            //当背景透明时去掉灰色蒙层
            activity.window.isNavigationBarContrastEnforced = false
        }
        //导航栏背景颜色透明
        activity.window.navigationBarColor = Color.TRANSPARENT
    }


    fun getNavigationBarHeight(context: Context): Int {
        val rid: Int =
            context.resources.getIdentifier("config_showNavigationBar", "bool", "android")
        return if (rid != 0) {
            val resourceId: Int =
                context.resources.getIdentifier("navigation_bar_height", "dimen", "android")
            context.resources.getDimensionPixelSize(resourceId)
        } else {
            0
        }
    }
}